//
//  THViewController.m
//  MonkeyTravel
//
//  Created by Wan on 16/1/7.
//  Copyright © 2016年 WanWanSui. All rights reserved.
//

#import "THViewController.h"

@interface THViewController ()

@end

@implementation THViewController

- (void)viewDidLoad {
        [super viewDidLoad];
        //    UIImage *image = [UIImage imageNamed:@"GoBack"];
        //    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        //
        //    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(leftBarAction:)];
        // Do any additional setup after loading the view.
        //统一设置标签栏/导航栏样式,通常是在AppDelegate中进行才会起作用
        //    [[UINavigationBar appearance] setBarTintColor:[UIColor cyanColor]];
        //    [[UITabBar appearance] setBarTintColor:[UIColor cyanColor]];
        
        self.navigationController.navigationBar.translucent = NO;
        [[self.navigationController navigationBar] setBarTintColor:[UIColor whiteColor]];
        [[self.tabBarController tabBar] setBarTintColor:[UIColor whiteColor]];
        
        NSDictionary *dict = [NSDictionary dictionaryWithObject:[UIColor blackColor] forKey:UITextAttributeTextColor];
        self.navigationController.navigationBar.titleTextAttributes = dict;
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeColor:) name:@"changeColor" object:nil];
        NSString *string = [[NSUserDefaults standardUserDefaults] objectForKey:@"night"];
        if ([string isEqualToString:@"yes"]) {
            self.view.backgroundColor = [UIColor blackColor];
            [[self.navigationController navigationBar] setBarTintColor:[UIColor blackColor]];
            [[self.tabBarController tabBar] setBarTintColor:[UIColor blackColor]];
            NSDictionary *dict = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor];
            self.navigationController.navigationBar.titleTextAttributes = dict;
        }
        
        
    }
    
    - (void)changeColor:(NSNotification *)notification {
        NSString *string = [notification object];
        if ([string isEqualToString:@"yes"]) {
            self.view.backgroundColor = [UIColor blackColor];
            [[self.navigationController navigationBar] setBarTintColor:[UIColor blackColor]];
            [[self.tabBarController tabBar] setBarTintColor:[UIColor blackColor]];
            NSDictionary *dict = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor];
            self.navigationController.navigationBar.titleTextAttributes = dict;
            
        } else {
            self.view.backgroundColor = [UIColor whiteColor];
            [[self.navigationController navigationBar] setBarTintColor:[UIColor whiteColor]];
            [[self.tabBarController tabBar] setBarTintColor:[UIColor whiteColor]];
            NSDictionary *dict = [NSDictionary dictionaryWithObject:[UIColor blackColor] forKey:UITextAttributeTextColor];
            self.navigationController.navigationBar.titleTextAttributes = dict;
        }
        //保存当前状态
        
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
